package com.boot.producer;

import com.boot.code.MqConstant;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * DESC: Rocket生产者
 *
 * @author WangJie
 * @date Created in 2025-03-04 20:19
 */

@Component
public class RocketProducer {
    private static final Logger logger = LoggerFactory.getLogger(RocketProducer.class);

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendMessage(String message) {
        logger.info("Sending message:'{}' to topic:'{}'", message, MqConstant.TOPIC);
        SendResult sendResult = rocketMQTemplate.syncSend(MqConstant.TOPIC, message);
        logger.info(String.valueOf(sendResult.getSendStatus()));
        logger.info(sendResult.getMsgId());
        logger.info(String.valueOf(sendResult.getQueueOffset()));
        logger.info(sendResult.getMessageQueue().getTopic());
        logger.info(String.valueOf(sendResult.getMessageQueue().getQueueId()));
    }
}
